import request from '@/utils/request';

export async function getCompany(token, companyID) {
  return await request.post('/api/1.0/company/user/list', {
    companyHsCode: companyID,
    token: token
  });
}

export async function getGSoptions(GSName) {
  return await request.post('/api/1.0/base/m812040iacbinfo/list', {
    departmentName: GSName
  });
}

export async function getDepartmentInfo(departID, token) {
  return await request.post(
    '/api/1.0/base/m812020bbinfocustom/parent/department/all',
    {
      departmentCode: departID,
      token: token
    }
  );
}

export async function getSSoptions(token, SSName) {
  return await request.post(
    '/api/1.0/base/m812020bbinfocustom/department/search',
    {
      departmentName: SSName,
      token: token
    }
  );
}

export async function getSWoptions(SWName) {
  return await request.post('/api/1.0/base/m812030tbinfo/list', {
    departmentName: SWName
  });
}

export async function getUserInfo() {
  return await request.post('/api/1.0/manager/user/register/info', {});
}

//修改用户信息
export async function changeUser(
  jcname,
  swCode,
  address,
  contactname,
  contact
) {
  return await request.post('/api/1.0/manager/user/registerinfo/update', {
    companyName: jcname,
    buisnessDepartmentId: swCode,
    address: address,
    contactsName: contactname,
    contactsPhone: contact
  });
}

//修改用户密码
export async function changePass(oldPass, newPass) {
  return await request.post('/api/1.0/manager/user/change/password', {
    oldPassWord: oldPass,
    newPassWord: newPass
  });
}

//修改用户密码
export async function changeRegisterPass(token, phone, code, newPass) {
  return await request.post('/api/1.0/manager/user/reset/password', {
    mobile: phone,
      securityCode: code,
    newPassWord: newPass,
    token: token
  });
}

//获取手机验证码
export async function getPhoneCode(token, phoneNum) {
  return await request.post('/smscode/send', {
    token: token,
    phoneNumber: phoneNum
  });
}

//提交注册用户
export async function register(
  token,
  hsCode,
  hsName,
  comName,
  swCode,
  contactname,
  contactphone,
  address,
  name,
  phone,
  key,
  password
) {
  return await request.post('/api/1.0/manager/user/regist', {
    token: token,
    companyHsCode: hsCode,
    companyHsName: hsName,
    companyName: comName,
    buisnessDepartmentId: swCode,
    contactsName: contactname,
    contactsPhone: contactphone,
    address: address,
    eb1: name,
    eb2: phone,
    securityCode: key,
    userPassword: password
  });
}

// 手机号验证
export function isvalidPhone(str) {
  const reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
  if (!reg.test(str)) {
    return false;
  } else {
    var info = JSON.parse(localStorage.getItem('CompanyInfo'));
    if (str == info.corporationPhone) {
      return true;
    } else {
      return false;
    }
  }
}


/**
 * 获取企业信息
 * /company/register/step2
 * @param companyHsCode
 * @returns {Promise<*|void>}
 */
export let getCompanyInfo = async (companyHsCode)=>{
  return request.post('/api/1.0/base/m812011companyinfowmzx/list',{
      companyHsCode: companyHsCode,
      token:localStorage.getItem('token')

  })
}


/**
 * 企业备案
 * @param companyName
 * @param token
 * @returns {Promise<*>}
 */
export let changeCompanyName = async (companyName,companyCode,token)=>{
  return request.post('/api/1.0/company/user/change/companyname',{
    token:localStorage.getItem('token'),
      companyName,
      companyCode
  })
}